package com.cxyd.modules.job.utils;

import java.util.Random;

public class RandomStringGenerator {
    // 定义包含所有可能字符的字符串
    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    public static void main(String[] args) {
        int length = 8; // 字符串长度
        String randomString = generateRandomString(length);
        System.out.println("生成的8位随机字符串: " + randomString);
    }

    public static String generateRandomString(int length) {
        Random random = new Random();
        StringBuilder sb = new StringBuilder(length);

        for (int i = 0; i < length; i++) {
            // 从 CHARACTERS 中随机选择一个字符
            int randomIndex = random.nextInt(CHARACTERS.length());
            char randomChar = CHARACTERS.charAt(randomIndex);
            sb.append(randomChar);
        }

        return sb.toString();
    }
}
